import worker, { MessageEvents } from '@ohos.worker';

// 创建worker线程中与主线程通信的对象
const workerPort = worker.workerPort
const TAG :string= 'tencent'

// worker线程接收主线程信息
workerPort.onmessage = (e: MessageEvents) =>  {
    // data：主线程发送的信息
    let data:ESObject = e.data;
    console.log(TAG,"worker.ts onmessage");

    // worker线程向主线程发送信息
    workerPort.postMessage("123")
}

// worker线程发生error的回调
workerPort.onerror= (e)=> {
    console.log(TAG,"worker.ts onerror");
}